const User = require("../database/models/user");
const jwt = require("jsonwebtoken");//令牌库
//生成令牌：
async function generateToken(req, res, next) {
    const data = await User.findAll({
        where: {
            account: req.body.account,
        }
    })
    const token = jwt.sign({
        id: data[0].dataValues.id,
        account: data[0].dataValues.account,
        exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 3,
        // 生成为期三天的令牌
    }, "hds")
    req.token = token;
    return next();
}
module.exports = generateToken;

